#include "CutTool.h"

using namespace Editor;

CutTool::CutTool(Editor::EditWidget* _widget)
    : buttonPressed(false), widget(_widget), cutEdge(0)
{
}

void CutTool::leftButtonPressed()
{
    cutter = new QGraphicsLineItem(mousePos.x(), mousePos.y(), mousePos.x(), mousePos.y());
    cutter->setPen(QPen(Qt::black, 1.0));
    widget->scene()->addItem(cutter);
    buttonPressed = true;
}

void CutTool::leftButtonReleased()
{
    buttonPressed = false;
}

void CutTool::rightButtonPressed()
{
    if(cutEdge != 0)
        cutEdge->setSelected(false);
    
    cutEdge = widget->getNearEdge(mousePos);
    
    if(cutEdge != 0)
        cutEdge->setSelected(true);
}

void CutTool::rightButtonReleased()
{

}

void CutTool::mouseMove(QPointF p)
{
    mousePos = p;
    
    if(buttonPressed)
        cutter->line().setP2(p);
    
    emit sceneChanged();
}

